/*
 * @Author: yanjikun
 * @Date: 2022-05-16 17:28:49
 * @LastEditors: yanjikun
 * @LastEditTime: 2022-06-13 15:34:39
 * @Description: file content
 */

import { api } from '@/api'
import { YAxios } from '@/utils/http/request'

export function userCreate(params: API.UserCreateParams) {
  return YAxios(
    {
      url: `${api.user}/add`,
      method: 'post',
      data: params,
    },
    { successMsg: '新增成功！' },
  )
}

export function userListByOrg(params: API.UserListParams) {
  return YAxios<API.UserListResult>({
    url: `${api.user}/${params.org}/ofOrg`,
    method: 'get',
  })
}

export function userInfo(params: API.UserInfoParams) {
  return YAxios<API.UserListItem>({
    url: `${api.user}/${params.id}/byId`,
    method: 'get',
  })
}

export function userUpdate(params: API.UserCreateParams) {
  return YAxios(
    {
      url: `${api.user}/info/${params.id}`,
      method: 'put',
      data: params,
    },
    { successMsg: '修改成功！' },
  )
}

export function userDelete(params: API.UserInfoParams) {
  return YAxios(
    {
      url: `${api.user}/${params.id}`,
      method: 'delete',
    },
    { successMsg: '删除成功！' },
  )
}

export function userResetPassword(params: API.UserResetPasswordParams) {
  return YAxios(
    {
      url: `${api.user}/${params.login}/resetPassword`,
      method: 'post',
      data: params,
    },
    { successMsg: '重置密码成功！' },
  )
}

export function userDisable(params: API.UserInfoParams) {
  return YAxios(
    {
      url: `${api.user}/${params.id}/disable`,
      method: 'post',
    },
    { successMsg: '禁用成功！' },
  )
}

export function userEnable(params: API.UserInfoParams) {
  return YAxios(
    {
      url: `${api.user}/${params.id}/enable`,
      method: 'post',
    },
    { successMsg: '启用成功！' },
  )
}
